home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Count lines in file?
- Date: Tue, 02 Jan 96 16:55:50 GMT
- Organization: none
- Distribution: world
- Message-ID: <820601750snz@genesis.demon.co.uk>
- References: <4bfnqu$btj@news1.netzone.com> <4bi4nr$3qe@castle.nando.net> <4bk30e$l08@news1.netzone.com> <Pine.A32.3.91.951224222853.23094E@red.weeg.uiowa.edu> <4bm9tk$h5a@crl14.crl.com> <820334651snz@genesis.demon.co.uk> <4c4v8b$kb6@crl5.crl.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4c4v8b$kb6@crl5.crl.com> kossick@crl.com "Paul J. Kossick" writes:
-
- >That's an interesting point I thought of when talking to someone else
- >about this via E-Mail...I would think that fgets would be SLOWER than
- >getc, since it actually has to execute code similar to getc to fill the
- >buffer in the first place...as well as other work such as checking to see
- >if the buffer is full.
-
- Both getc and fgets have to perform these checks on every call (or macro
- invocation). Since fgets should be called fewer times than getchar the
- fgets version may well have lower overhead if the library is implemented
- reasonably.
-
- > Since you don't NEED to retain the lines intact
- >in order to count them, a buffer is basicly surplusage.
-
- There are overheads whichever way you do it, it just depends which are
- greater. The fread solution gives the implementation the best chance of
- avoiding this extra buffering.
-
- >Oh, before someone else points it out: One problem with getc might be if
- >the last line of the program doesn't have a terminating newline
- >character, i.e. it terminates with the eof. This could cause the count
- >to be off by one in such cases.
-
- It depends on your definition of a 'line'. It is reasonable to say is that
- of the final sequence of characters is not terminated by '\n' it is not
- a valid line.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-